﻿#region License
/* Copyright (C) 2009 Tim Coulter
 * 
 * This file is part of ExtremeML.
 * 
 * ExtremeML is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License, as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
*/
#endregion

namespace ExtremeML.Spreadsheet
{
	// This is a partial class that adds custom functionality to its auto-generated partner.
	public sealed partial class SharedStringItemWrapper
	{
		#region Custom Properties

		/// <summary>
		/// Gets or sets the contained string value.
		/// </summary>
		internal string Value
		{
			get { return Text.Value; }
			set { Text.Value = value; }
		}

		/// <summary>
		/// Gets the number of wrapper instances that hold references to this instance.
		/// </summary>
		internal int ReferenceCount { get; private set; }

		#endregion
		#region Custom Methods

		/// <summary>
		/// Increments the reference count to record one additional consumer of this instance.
		/// </summary>
		internal void IncrementReferenceCount()
		{
			ReferenceCount++;
		}

		/// <summary>
		/// Decrements the reference count to record the removal of one consumer of this instance.
		/// </summary>
		internal void DecrementReferenceCount()
		{
			ReferenceCount--;

			// When the last consumer of this instance is removed it can be deleted.
			if (ReferenceCount == 0)
			{
				Remove();
			}
		}

		/// <summary>
		/// Returns the index of this item in its collection.
		/// </summary>
		/// <returns>The zero-based index of this item in its collection.</returns>
		internal int GetIndex()
		{
			return ((SharedStringItemWrapperCollection)Parent).GetIndexOf(this);
		}

		#endregion
		#region Overrides


		#endregion
		#region Implementation Methods


		#endregion
		#region Static Methods


		#endregion
	}
}
